package com.wifi.books.service.impl;

import com.wifi.books.dao.BookDAO;
import com.wifi.books.entity.BookEntity;
import com.wifi.books.service.IBookService;

import java.sql.SQLException;
import java.util.List;

public class IBookServiceImpl implements IBookService {
    BookDAO bookDAO= BookDAO.getBookDAO();

    @Override
    public List<Object> queryBookList(Integer start,Integer pageSize) throws SQLException {
            List<Object> list = bookDAO.queryBookList(start, pageSize);

        return list;
    }

    @Override
    public Integer booksCount() {
        try {
            Integer integer = bookDAO.booksCount();
            return integer;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public BookEntity queryBookByBookId(Integer bookId) {
        try {
            BookEntity book = bookDAO.queryBookById(bookId);
            return book;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public Integer updateBook(Integer bid, BookEntity book) {
        try {
            Integer integer = bookDAO.updateBook(bid, book);
            return integer;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public Integer addBook(BookEntity bookEntity) {
        try {
            Long aLong = bookDAO.addBook(bookEntity);
            return aLong.intValue();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Object> queryBookByInfo(String bookInfo) {
        List<Object> list=null;
        try {
           list = bookDAO.queryBookByInfo(bookInfo);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public List<Object> queryBookByType(Integer ftypeId,Integer start ,Integer pageSize) {
        List<Object> list = null;
        try {
            list = bookDAO.queryBookListByBookType(ftypeId, start, pageSize);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public List<Object> queryBookByTwoType(Integer ftypeId, Integer stypeId, Integer start, Integer pageSize) {
        List<Object> list = null;
        try {
            list = bookDAO.queryBookListByBookType(ftypeId, stypeId, start, pageSize);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }


}
